/**
 * 
 */
 $(function () {
 	layui.use(['element','layer'], function(){
  		element = layui.element;
  		layer=layui.layer;
  
	});
	
	
	    //触发事件
tab = {
        tabAdd: function(title,url,id){
          var li = $("li[lay-id="+id+"]").length;
			if(li>0){
			 	//切换到指定Tab项
         		 element.tabChange('tngou_tab', id); //切换到：用户管理
			}else{
			//新增一个Tab项
		      element.tabAdd('tngou_tab', {
		            title: title 
		            ,content: '<iframe tab-id="'+id+'" frameborder="0" src="'+url+'" scrolling="yes" class="tngou-iframe"></iframe>'
		            ,id: id
		       })
			
			}
	      
          
        }
        ,tabDelete: function(othis){
 
          othis.addClass('layui-btn-disabled');
        }
        ,tabChange: function(id){
          //切换到指定Tab项
          element.tabChange('tngou_tab', id); //切换到：用户管理
        }
};
	
	
	
	 $('.tngou-left-open i').click(function(event) {
        if($('.layui-side').css('left')=='0px'){
            $('.layui-side').animate({left: '-150px'}, 100);
             $('.layui-side a').animate({left: '150px'}, 100);
             $('.layui-side .tngou-left-open i').css({width: '50px',float:'right'});
             $('.layui-side .layui-nav-item').removeClass('layui-nav-itemed');
             $('.layui-side cite').hide();
             $('.layui-side .layui-nav-more').hide();  
             $('.layui-body').animate({left: '50px'}, 100);
             $('.layui-footer').animate({left: '50px'}, 100);
        }else{
            $('.layui-side a').animate({left: '0px'}, 100);
            $('.layui-side').animate({left: '0px'}, 100);
            $('.layui-side .tngou-left-open i').css({width: '200px',float:''});
             $('.layui-side cite').show();
             $('.layui-side .layui-nav-more').show();  
            $('.layui-body').animate({left: '200px'}, 100);   
             $('.layui-footer').animate({left: '200px'}, 100);      
        }

    });
    $(".layui-nav-item").click(function(event) {
       if($('.layui-side').css('left')!='0px'){
          $('.layui-side a').animate({left: '0px'}, 100);
            $('.layui-side').animate({left: '0px'}, 100);
             $('.layui-side .tngou-left-open i').css({width: '200px',float:''});
             $('.layui-side cite').show();
             $('.layui-side .layui-nav-more').show();  
            $('.layui-body').animate({left: '200px'}, 100);   
             $('.layui-footer').animate({left: '200px'}, 100);  
    
          }
   
     });
     
    $(".layui-side .layui-nav-item").mouseenter(function(){	
    	if($('.layui-side').css('left')!='0px'&&this.attributes['tips']&&this.attributes['tips'].value){
		  layer.tips(this.attributes['tips'].value, this,{time:2000});
		 }
	 });
	 
	 $(".layui-side .layui-nav-child a").click(function(){	
	 		var url = $(this).attr('_href');
            var title = $(this).find('cite').html();
            var index  = $('.layui-side .layui-nav-child a').index($(this));
            index= index+1;
          
            tab.tabAdd(title,url,index);
            tab.tabChange(index);
            
	  });
	  
 		 $(".tngou-layer").mouseenter(function(){	
	    	if(this.attributes['lay-text']&&this.attributes['lay-text'].value){
	  		  layer.tips(this.attributes['lay-text'].value, this,{tips: 3,time:2000});
	  		}
	  });
 });
 
 
 /*添加  table */
 function tngou_tab_add(title,url,index){
      tab.tabAdd(title,url,index);
      tab.tabChange(index);
 }
   
 /*弹出层*/
/*
    参数解释：
    title   标题
    url     请求的url
    id      需要操作的数据id
    w       弹出层宽度（缺省调默认值）
    h       弹出层高度（缺省调默认值）
*/
function tngou_win_show(title,url,w,h){
    if (title == null || title == '') {
        title=false;
    };
    if (url == null || url == '') {
        url="404.html";
    };
    if (w == null || w == '') {
        w=($(window).width()*0.9);
    };
    if (h == null || h == '') {
        h=($(window).height() - 50);
    };
    layer.open({
        type: 2,
        area: [w+'px', h +'px'],
        fix: false, //不固定
        maxmin: true,
        shadeClose: true,
        shade:0.4,
        title: title,
        content: url
    });
}

/*关闭弹出框口*/
function tngou_win_close(){
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
}
